//
//  myWebViewController.m
//  FinancialProduct
//
//  Created by Stella on 2017/9/1.
//  Copyright © 2017年 maq. All rights reserved.
//
#import "UIWebView+JavaScriptAlert.h"

#import "AFHTTPSessionManager.h"
#import "FileHandler.h"
#import "myWebViewController.h"
#import "SVProgressHUD.h"
@interface myWebViewController ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *mWebView;
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;

@property (strong,nonatomic)NSURLSessionDownloadTask *task;

@end

@implementation myWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSURLCache sharedURLCache] removeAllCachedResponses];
    NSLog(@"_urlString000=%@", _urlString);

    if (!_urlString||_urlString.length==0) {
        return;
    }
    if ([self.title isEqualToString:@"产品公告"]) {
        if (_isPDF) {
            NSCharacterSet *encodeUrlSet = [NSCharacterSet URLQueryAllowedCharacterSet];
            NSString *encodeUrl = [_urlString stringByAddingPercentEncodingWithAllowedCharacters:encodeUrlSet];
            NSLog(@"_urlString222=%@", encodeUrl);
            [_mWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:encodeUrl]]];
        }else{
            [_mWebView loadHTMLString:_urlString baseURL:nil];
        }
        
    }else{
        
       
        
        NSCharacterSet *encodeUrlSet = [NSCharacterSet URLQueryAllowedCharacterSet];
        NSString *encodeUrl = [_urlString stringByAddingPercentEncodingWithAllowedCharacters:encodeUrlSet];
        NSLog(@"_urlString222=%@", encodeUrl);
        [_mWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:encodeUrl]]];
        
//        NSString *path=[[NSBundle mainBundle]pathForResource:@"Contact(1)" ofType:@"html"];
//        NSString *html = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//        //加载js
//        [_mWebView loadHTMLString:html baseURL:[[NSBundle mainBundle] bundleURL]];
    }
    

    _mWebView.backgroundColor=[UIColor clearColor];
    //这句话很重要，webView是否是不透明的，no为透明 在webView下添加个imageView展示图片就可以了
    _mWebView.opaque=NO;
    self.mWebView.delegate = self;
    self.mWebView.scalesPageToFit = YES;
    [SVProgressHUD showInfoWithStatus:@"loading..."];
    
}

- (void)webViewDidStartLoad:(UIWebView *)webView{
    NSLog(@"webViewDidStartLoad");
}
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    NSLog(@"webViewDidFinishLoad");
//    CGSize contentSize = _mWebView.scrollView.contentSize;
//    CGSize viewSize = self.view.bounds.size;
//
//    NSLog(@"contentSize--%f",contentSize.width);
//    NSLog(@"viewSize---%f",viewSize.width);
//    float sfactor = viewSize.width / contentSize.width;//调整因子计算
//    
//    webView.scrollView.minimumZoomScale = sfactor;//最大调整参数设置为调整因子
//    webView.scrollView.maximumZoomScale = sfactor;//最小调整参数设置为调整因子
//    webView.scrollView.zoomScale = sfactor;
    
    
    [SVProgressHUD dismiss];

}

-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    NSLog(@"didFailLoadWithError:%@",error);
     [SVProgressHUD dismiss];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
